Overview
Theroom package provides room management functionality for collaborative sessions, including workspace isolation, client connections, and resource cleanup.
Types
Manager
Manages all active rooms and their lifecycle.Room
Represents a collaborative session with shared terminal and AI chat.Client
Represents a connected user in a room.RoomEvent
Events broadcast to room participants.AIMessage
AI chat message stored in room history.Manager Functions
NewManager
Creates a new room manager instance.string
URL for the AI worker service (empty string disables AI features)
*ai.Client
Shared AI client for all rooms
*log.Logger
Logger instance for room events
CreateRoom
Creates a new collaborative room with isolated workspace.string
required
Username of the room host
string
Room description (used to generate workspace name)
*Room: The created room with unique IDerror: If workspace creation fails
- Slugified description if provided (e.g., “my project” → “my-project”)
- Random readable name if empty (e.g., “swift-phoenix”, “cosmic-dragon”)
- Max 30 characters
GetRoom
Retrieves an existing room by ID.string
required
Unique room identifier
*Room: The requested roomerror:ErrRoomNotFoundif room doesn’t exist
LeaveRoom
Removes a client from a room and cleans up if empty.string
required
Room to leave
string
required
Client identifier
true if the room was destroyed (last client left)
Cleanup Actions:
- Closes terminal if exists
- Removes workspace directory
- Calls worker API to cleanup sandbox resources
- Deletes room from manager
GetAIClient
Retrieves the shared AI client.RoomCount
Returns the number of active rooms.Room Methods
AddClient
Adds a client to the room and broadcasts join event.*Client
required
Client to add (replaces existing client with same ID)
RemoveClient
Removes a client and broadcasts leave event.BroadcastEvent
Sends an event to all clients except one.RoomEvent
required
Event to broadcast
string
Client ID to exclude (typically the sender)
GetClients
Returns a copy of all connected clients.ClientCount
Returns the number of connected clients.SetAIMessages / GetAIMessages
Thread-safe AI message history management.Errors
Workspace Isolation
Each room gets an isolated workspace directory:- Production: Copies
/app/workspace-template/to/app/workspaces/{name}/ - Development: Creates empty directory in temp folder